window.stylePlugins = {};

/* 常用经过显示图层 下滑+渐变显示效果 */
stylePlugins.showHoverBox = function (hovers, hoverblock, hoverbox, morePara, callfuninfo)
{
	if(morePara == undefined)morePara = {};
	var fadeok = 0;
	var hoverTit = "st-hoverTit";
	if(morePara.fadeok)fadeok = morePara.fadeok;
	if(morePara.hoverTit)hoverTit = morePara.hoverTit;
	if(hovers == 1){
		var showfs = 200;
		var hoverTitDown = "st-hoverTitDown";
		if(morePara.showfs)showfs = morePara.showfs;
		if(morePara.hoverTitDown)hoverTitDown = morePara.hoverTitDown;
		$(hoverblock).mouseenter(function(e){
			$(this).find(hoverTitDown).addClass(hoverTit);
			$(this).find(hoverbox).slideDown(showfs);
			if(callfuninfo)callfuninfo(1, this, e);
		});
		$(hoverblock).mouseleave(function(){
			$(this).find(hoverTitDown).removeClass(hoverTit);
			$(this).find(hoverbox).stop(true,true).slideUp(showfs);
			if(callfuninfo)callfuninfo(2, this, e);
		});
	}else if(hovers == 2){
		var showfs = "";
		var hoverTitShow = "st-hoverTitShow";
		if(morePara.showfs)showfs = morePara.showfs;
		if(morePara.hoverTitShow)hoverTitShow = morePara.hoverTitShow;
		$(hoverblock).mouseenter(function(e){
			$(this).find(hoverTitShow).addClass(hoverTit);
			//淡入淡出
			if (fadeok == 1) {
				$(this).find(hoverbox).fadeIn(showfs);
			}else{
                if(showfs == "")showfs = 0;
				$(this).find(hoverbox).show(showfs);
			}
			if(callfuninfo)callfuninfo(1, this, e);
		});	
		$(hoverblock).mouseleave(function(){
			$(this).find(hoverTitShow).removeClass(hoverTit);
			//淡入淡出
			if (fadeok == 1) {
				$(this).find(hoverbox).fadeOut(showfs);
			}else{
                if(showfs == "")showfs = 0;
				$(this).find(hoverbox).stop(true,true).hide(showfs);
			}
			if(callfuninfo)callfuninfo(2, this, e);
		});
	}
}

/* 常用点击显示图层 下滑+渐变显示效果 */
stylePlugins.showClickBox = function (clicks, clicktit, clickbox, morePara, callfuninfo)
{
	if(morePara == undefined)morePara = {};
	var fadeok = 0;
	var clickTit = "st-clickTit";
	if(morePara.fadeok)fadeok = morePara.fadeok;
	if(morePara.clickTit)clickTit = morePara.clickTit;
	if(clicks == 1){
		var showfs = 200;
		if(morePara.showfs)showfs = morePara.showfs;
		$(clicktit).click(function(e){
			var display =$(this).next(clickbox).css('display');
			if(display == 'none'){
				$(this).addClass(clickTit);
			    $(this).next(clickbox).slideDown(showfs);
				if(callfuninfo)callfuninfo(1, this, e);
			}else{
				$(this).removeClass(clickTit);
				$(this).next(clickbox).stop(true,true).slideUp(showfs);
				if(callfuninfo)callfuninfo(2, this, e);
			}
		});
	}else if(clicks == 2){
		var showfs = "";
		if(morePara.showfs)showfs = morePara.showfs;
		$(clicktit).click(function(e){
			var display =$(this).next(clickbox).css('display');
			if(display == 'none'){
				$(this).addClass(clickTit);
				//淡入淡出
				if (fadeok == 1) {
					$(this).find(hoverbox).fadeIn(showfs);
				}else{
                    if(showfs == "")showfs = 0;
					$(this).next(clickbox).show(showfs);
				}
				if(callfuninfo)callfuninfo(1, this, e);
			}else{
				$(this).removeClass(clickTit);
				//淡入淡出
				if (fadeok == 1) {
					$(this).find(hoverbox).fadeOut(showfs);
				}else{
                    if(showfs == "")showfs = 0;
					$(this).next(clickbox).stop(true,true).hide(showfs);
				}
				if(callfuninfo)callfuninfo(2, this, e);
			}
		});
	}
	
}

// 经过点击显示图层区块效果集
// stylePlugins.showBoxData({type:2, show:1, title:'#headdiv', content:'#headdivdef'}, function(){$('#headdiv').hide();})
// stylePlugins.showBoxData({type:2, show:1, title:'#openhead', content:'#headdiv'}, function(){$('#headdivdef').hide();})
// stylePlugins.showBoxData({type:4, show:1, title:'#searchok', titleClass:'options-visible', content:'#searchdiv', contentClass:'options-visible'})
// stylePlugins.showBoxData({type:4, show:0, title:'#searchok', titleClass:'options-visible', content:'#searchdiv', contentClass:'options-visible'});stylePlugins.endMaoPao();
stylePlugins.showBoxData = function (data, callfuninfo)
{
	var type = 0;
	var isopen = 0;
	var tit = "";
	var titclass = "";
	var div = "";
	var divclass = "";
	if(data.type)type = data.type;
	if(data.show)isopen = data.show;
	if(data.title)tit = data.title;
	if(data.titleClass)titclass = data.titleClass;
	if(data.content)div = data.content;
	if(data.contentClass)divclass = data.contentClass;
	// 显示效果
	if(type == 1){
		var showfs = "";
		if(data.showMode)showfs = data.showMode;
		// 淡入淡出效果
		if(isopen == 4){
			if(showfs == "")showfs = 500;
			if(titclass)$(tit).toggleClass(titclass);
			$(div).stop(true,true).fadeOut(showfs);
			if(callfuninfo)callfuninfo();
		// 淡入淡出效果
		}else if(isopen == 3){
			if(showfs == "")showfs = 500;
			if(titclass)$(tit).toggleClass(titclass);
			$(div).fadeIn(showfs);
			if(callfuninfo)callfuninfo();
		// 直接显示效果
		}else if(isopen == 2){
			if(titclass)$(tit).toggleClass(titclass);
			$(div).stop(true,true).toggle(showfs);
			if(callfuninfo)callfuninfo();
		// 直接显示效果
		}else if(isopen == 1){
            if(showfs == "")showfs = 0;// show为0时无过滤直接显示
			if(titclass)$(tit).addClass(titclass);
			$(div).show(showfs);
			if(callfuninfo)callfuninfo();
		// 直接显示效果
		}else{
            if(showfs == "")showfs = 0;// show为0时无过滤直接隐藏
			if(titclass)$(tit).removeClass(titclass);
			$(div).stop(true,true).hide(showfs);
			if(callfuninfo)callfuninfo();
		}
	}	
	
	// 下滑展开效果
	if(type == 2){
		var showfs = 200;
		if(data.showMode)showfs = data.showMode;
		if(isopen == 2){
			if(titclass)$(tit).toggleClass(titclass);
			$(div).stop(true,true).slideToggle(showfs);
			if(callfuninfo)callfuninfo();
		}else if(isopen == 1){
			if(titclass)$(tit).addClass(titclass);
			$(div).slideDown(showfs);
			if(callfuninfo)callfuninfo();
		}else{
			if(titclass)$(tit).removeClass(titclass);
			$(div).stop(true,true).slideUp(showfs);
			if(callfuninfo)callfuninfo();
		}

	}
	
	// 动画移入效果
	if(type == 3){
		var showfs = "";
		if(data.showMode)showfs = data.showMode;
		if(isopen == 1){
			if(titclass)$(tit).addClass(titclass);
            if($(div + ":animated").length == 0) {
                $(div).fadeIn();
                if(showfs == "up"){
                    $(div).animate({"bottom": 0});
                }else if(showfs == "left"){
                    $(div).animate({"left": 0});
                }else{
                    $(div).animate({"right": 0});	
                }
            }
			if(callfuninfo)callfuninfo();
		}else{
			if(titclass)$(tit).removeClass(titclass);
            if($(tit + ":animated").length == 0) {
                $(tit).animate({"isAnimate": "1"});// 鼠标移开时，默认标题没有动画，通过设置标题动画来限制移开动画只执行一次
                if(showfs == "up"){
                    $(div).animate({"bottom": "-100%"});
                }else if(showfs == "left"){
                    $(div).animate({"left": "-100%"});
                }else{
                    $(div).animate({"right": "-100%"});
                }
            }
			if(callfuninfo)callfuninfo();
		}

	}
	
	// 自定义样式效果
	if(type == 4){
		if(isopen == 2){
			if(titclass)$(tit).toggleClass(titclass);
			if(divclass)$(div).toggleClass(divclass);
			if(callfuninfo)callfuninfo();
		}else if(isopen == 1){
			if(titclass)$(tit).addClass(titclass);
			if(divclass)$(div).addClass(divclass);
			if(callfuninfo)callfuninfo();
		}else{
			if(titclass)$(tit).removeClass(titclass);
			if(divclass)$(div).removeClass(divclass);
			if(callfuninfo)callfuninfo();
		}
	}	
}

/* 常用公告文本向上滚动效果 */
// <ul class="st-sbox" data-st-top="52"><li class="st-slist">
stylePlugins.textScrollTop = function (obj)
{
	setInterval(function(){
		var top = $(obj).find(".st-sbox:first").data("st-top");
		$(obj).find(".st-sbox:first").animate({
			marginTop: "-"+top+"px"
		}, 500, function() {
			$(this).css({
				marginTop: "0px"
			}).find(".st-slist:first").appendTo(this);
		});	
	}, 3000);
}

/*点击向左展开菜单选项*/
stylePlugins.openSelectBlock = function ()
{
	/*打开选项*/
	$(".st-openSelect").click(function() {
		$(this).next(".st-selectBlock").fadeIn();
		$(this).next(".st-selectBlock").find(".st-selectBox").animate({"right": 0});
	});
	/*关闭选项*/
	$(".st-selectBlock").click(function() {
		stylePlugins.closeMenuSelect();
	});
	$(".st-selectBlock .st-selectBox").click(function() {
		event.stopPropagation();
	});
}
stylePlugins.closeMenuSelect = function ()
{
	$(".st-selectBlock").fadeOut();
	$(".st-selectBlock .st-selectBox").animate({"right": "-100%"});
}

/* 选项卡 */
stylePlugins.selectTablist = function (that, aniok, showfs)
{
    if (aniok == undefined) aniok = 1;
    if (showfs == undefined) showfs = "right";

    //获取点击的元素给其添加样式，将其兄弟元素的样式移除
    $(that).addClass("st-active").siblings().removeClass("st-active");

    //获取选中元素的下标
    var index = $(that).index();

    //显示当前元素下标对应的内容，将其兄弟元素内容隐藏
    $(".st-tabBlock .st-contentBox .st-listBox").eq(index).addClass("st-active").siblings().removeClass("st-active");
    if (aniok == 1) {
        if ($(".st-tabBlock .st-contentBox .st-listBox:eq(" + index + "):animated").length == 0) {
            if (showfs = "right") {
                $(".st-tabBlock .st-contentBox .st-listBox").eq(index).animate({ left: "0" }).siblings().css("left", "-100%");
            } else {
                $(".st-tabBlock .st-contentBox .st-listBox").eq(index).animate({ right: "0" }).siblings().css("right", "-100%");
            }
        }
    }
}

// 防止冒泡
stylePlugins.endMaoPao = function ()
{
	var evt = evt || window.event; //获取event对象
    if (evt.preventDefault) {
        evt.preventDefault(); //非IE浏览器
 　　} else {
        evt.returnValue = false; //在早期的IE版本中
　　 }
	event.stopPropagation ? event.stopPropagation() : (event.cancelBubble = true); //阻止事件冒泡	
}

/* 分享弹层 ******************************************************************************* 
** <div class="st-shareBox">
**     <div class='st-share-bg'></div>
**     <div class='st-share-arrow'></div>
**     <div class='st-share-content'>请点击右上角<br/>通过【发送给朋友】<br/>邀请好友购买</div>
** </div>
*****************************************************************************************/
stylePlugins.userShare = function userShare()
{
	$('.st-share').click(function() {
		$('.st-shareBox').fadeIn(200)
	});
	$('.st-shareBox').click(function() {
		$('.st-shareBox').hide()
	})	
}

// 获取元素高度
stylePlugins.getHeight = function (obj)
{
	var height = $(obj).height();	
	
	return height;
}

// 设置元素高度
stylePlugins.setHeight = function (obj,height)
{
	$(obj).height(height);
}

// 通过获取指定元素的高度来加载设置当前元素高度
stylePlugins.loadHeight = function()
{
	var setObj = $(".st-setHeight");
	var getObj = $(".st-getHeight");
	$.each(setObj, function(i, obj){
		var getHeight = $(getObj[i]).height();
		$(obj).height(getHeight);
    });
}

// 点击设置css样式效果
stylePlugins.setClassStyle = function (id, setclass, remclass)
{
	$(id).addClass(setclass);
	$(id).removeClass(remclass);
}
stylePlugins.openClassStyle = function (id, setclass)
{
	$(id).addClass(setclass);
}
stylePlugins.colseClassStyle = function (id, setclass)
{
	$(id).removeClass(setclass);
}

// 经过后当前绑定class样式效果
stylePlugins.hoverClassStyle = function (id, active)
{
	if(active == null)active = 'st-hover';
	$(id).addClass(active).siblings('.'+active).removeClass(active);	
}

// 滚动条滚动到指定元素触发
stylePlugins.scrollFlashStyle = function (block)
{
	// 设置当前动画块的高度
	var scrollHeight = $(block).height();
	$(block).height(scrollHeight);
	
	// 触发滚动后的动画效果
	$(document).scroll(function() {
		sTop = $(this).scrollTop(); //获取滚动条的位置
		var sh = $(window).height();//视口高度
		var ft = $(block).offset().top//指定元素距离文档顶部高度
		
		// 滚动条位置 大于 指定元素减去 视口高度时
		if (sTop > (ft - sh)) { //当底部出现在视口时 触发
			if(!$(block).hasClass('st-hover')){
				$(block).hide();// 隐藏元素
				$(block).fadeIn(1500); // 开始淡入	
			}
			$(block).addClass('st-hover');// 动画效果
		}
	});
}

// 设置当前URL参数
stylePlugins.setUrlPara = function (name, value) {
	if (window.location.search != "") {
		var rurl = window.location.href.split('?');
		var querys = rurl[1].split('&');
		var r = "";
		var has = false;
		for (var i = 0; i < querys.length; i++) {
			var item = querys[i].split('=');
			if (item[0] == name) {
				item[1] = value;
				has = true;
			}
			r += "&" + item[0] + "=" + item[1];
		}
		if (has == false) {
			r += "&" + name + "=" + value;
		}
		r = r.substr(1);
		var url = rurl[0] + "?" + r;
	} else {
		var url = window.location.href + "?" + name + "=" + value;
	}
	return url;
}

// 移动端响应式代码 最大宽度为750 1rem = 50px：
stylePlugins.getMobileResponWeb = function(maxWidth, prop)
{
    if(prop == undefined)prop = .13333334;
    var b = document.documentElement,
            a = function() {
                var a = b.getBoundingClientRect().width;
                b.style.fontSize = prop * (maxWidth <= a ? maxWidth : a) + "px"
            },
            c = null;
    window.addEventListener("resize",
            function() {
                clearTimeout(c);
                c = setTimeout(a, 300)
            });
    a()
}

// 替换后端动态URL参数
stylePlugins.repDynamicUrl = function (url, params, repChar) {
	if(repChar == undefined) {
		repChar = {};
		repChar.left = "{";
		repChar.right = "}";
	}
    for (var index in params) {
        url = url.replace(repChar.left + index + repChar.right, params[index]);
    }

    return url;
}

/******************************************************END*************************************************************************/
